# Huawei Technologies Co.,Ltd.

set(THROWDYN_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/throwdyn.txt)
set(THROWDYN_BIN ${CMAKE_CURRENT_BINARY_DIR}/throwdyn.abc)
set(THROWDYN_JS ${CMAKE_CURRENT_SOURCE_DIR}/throwdyn.js)
set(THROWDYN_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false ${THROWDYN_BIN} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${THROWDYN_OUTPUT}
    COMMENT "running javascript throwdyn testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${THROWDYN_JS} --output ${THROWDYN_BIN}
    COMMAND rm -f ${THROWDYN_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} 2>&1 > ${THROWDYN_OUTPUT}
    COMMAND bash ${THROWDYN_VERIFY} ${THROWDYN_OUTPUT}
)
add_custom_target(throwdyn
    DEPENDS ${THROWDYN_OUTPUT} ${THROWDYN_VERIFY}
)
add_dependencies(throwdyn es2panda ark)
add_dependencies(ecmascript_common_tests throwdyn)
